﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;

namespace CoreEx.Common.Validation
{
    /// <summary>
    /// Represents a class that is capable of rewriting the expression tree in such 
    /// as way that member expressions don't return <c>null</c> values unless an explicit
    /// check for <c>null</c> is intended.
    /// </summary>
    public interface IRuleRewriter
    {
        /// <summary>
        /// Rewrites the <see cref="ruleExpression"/> by replacing any <see cref="MemberExpression"/> with a <see cref="ConditionalExpression"/>
        /// where the member is not explicitly checked for <c>null</c>.
        /// </summary>
        /// <typeparam name="T">The target type to validate.</typeparam>
        /// <param name="ruleExpression">The validation expression.</param>
        /// <param name="targetProperties">The target properties for the <paramref name="ruleExpression"/> that are candidates for rewriting.</param>
        /// <returns><see cref="Expression{TDelegate}"/></returns>
        Expression<Func<T, bool>> Rewrite<T>(Expression<Func<T, bool>> ruleExpression, IEnumerable<PropertyInfo> targetProperties);
    }
}
